builderparser: Allow bind-source without bind-property
authorMohammed Sadiq <sadiq@sadiqpk.org>
Wed, 7 Aug 2019 02:12:03 +0000 (07:42 +0530)
committerMohammed Sadiq <sadiq@sadiqpk.org>
Sat, 10 Aug 2019 13:31:36 +0000 (19:01 +0530)
This allow users to bind same property of two objects with only
specifing “name” and “bind-source” in UI file.

Fixes https://gitlab.gnome.org/GNOME/gtk/issues/2080

gtk/gtkbuilder.c
gtk/gtkbuilderparser.c
gtk/tools/gtk4builder.rng

index 138cf07c9739ba6245f8f7304608d3acc6d9c165..220a51c33cab0743bb42be6a4288b1a45eb67641 100644 (file)
  *
  * It is also possible to bind a property value to another object's
  * property value using the attributes
- * "bind-source" to specify the source object of the binding,
- * "bind-property" to specify the source property and optionally
- * "bind-flags" to specify the binding flags
+ * "bind-source" to specify the source object of the binding, and
+ * optionally, "bind-property" and "bind-flags" to specify the
+ * source property and source binding flags respectively.
  * Internally builder implement this using GBinding objects.
  * For more information see g_object_bind_property()
  *
index fc1c80db28b3a22c6e768dbc3453a1db68aa74c8..8a5a1608d60e28d88990fef005d790529a4bc4ef 100644 (file)
@@ -598,7 +598,7 @@ parse_property (ParserData   *data,
 
   g_markup_parse_context_get_position (data->ctx, &line, &col);
 
-  if (bind_source && bind_property)
+  if (bind_source)
     {
       BindingInfo *binfo;
 
@@ -606,17 +606,17 @@ parse_property (ParserData   *data,
       binfo->target = NULL;
       binfo->target_pspec = pspec;
       binfo->source = g_strdup (bind_source);
-      binfo->source_property = g_strdup (bind_property);
+      binfo->source_property = bind_property ? g_strdup (bind_property) : g_strdup (name);
       binfo->flags = bind_flags;
       binfo->line = line;
       binfo->col = col;
 
       object_info->bindings = g_slist_prepend (object_info->bindings, binfo);
     }
-  else if (bind_source || bind_property)
+  else if (bind_property)
     {
       error_missing_attribute (data, element_name,
-                               (bind_source) ? "bind-property" : "bind-source",
+                               "bind-source",
                                error);
       return;
     }
@@ -626,7 +626,7 @@ parse_property (ParserData   *data,
   info->pspec = pspec;
   info->text = g_string_new ("");
   info->translatable = translatable;
-  info->bound = (bind_source && bind_property);
+  info->bound = bind_source != NULL;
   info->context = g_strdup (context);
   info->line = line;
   info->col = col;
index 032d84d142cdf3f1087de5d9dbf4fb8b3dc08f0d..125051511c385cdb680b5867d075df482b236d16 100644 (file)
           <attribute name="bind-source">
             <text/>
           </attribute>
-          <attribute name="bind-property">
-            <text/>
-          </attribute>
+          <optional>
+            <attribute name="bind-property">
+              <text/>
+            </attribute>
+          </optional>
           <optional>
             <attribute name="bind-flags">
               <text/>